/**
 * 数据库连接
 */
 const config = require('./index');
 const log4js = require('../utils/log4j')
 const mongoose = require('mongoose');
 const User = require('../models/userSchema')
 const Counter = require('../models/counterSchema')
 const md5 = require('md5')
 
 async function main() {
   await mongoose.connect(config.URL);
 }

 main()
 .then(async(res) => {
  log4js.info('***数据库连接成功***')
  log4js.info('---开始初始化用户---')
  await User.create({
    userId: 1,
    userName:'omega',
    userPwd: md5('omega'),
    userEmail: 'omega@imooc.com',
    role: 0, //默认普通用户
  })
  log4js.info('---初始化用户完成---')
 })
 .catch(err => log4js.error('***数据库连接失败***'));
